package io;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class CopyFIleTest {

    public static void main(String[] args) throws IOException {
        final String scrFileName = "C:\\Users\\win10\\Desktop\\充值回调-来账识别报文.txt";
        final String dstFileName = "C:\\Users\\win10\\Desktop\\新建文本文档.txt";
        FileInputStream fileInputStream = new FileInputStream(scrFileName);
        FileOutputStream fileOutputStream = new FileOutputStream(dstFileName);
        FileChannel readChannel = fileInputStream.getChannel();
        FileChannel writeChannel = fileOutputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        int i = 0;
        while (true){
            buffer.clear();
            //从输入channel读取数据到buffer中
            if (readChannel.read(buffer)==-1){
                break;
            }
            buffer.flip();
            //将buffer中得数据写入writeChannel中
            writeChannel.write(buffer);
        }

        fileInputStream.close();
        fileOutputStream.close();
    }


}
